{extend name="layout:base" /}
{block name="page_content"}
  <form class="form-horizontal adminform" id="model-form" method="post" action="">
    <div class="form-group">
      <label class="col-sm-2 control-label no-padding-right" for="form-field-1">
        旧密码：
      </label>
      <div class="col-sm-10">
        <input type="password" name="old_password" placeholder="请输入您的登录密码" class="col-xs-10 col-sm-5" value="" />
      </div>
    </div>
    <div class="space-4"></div>

    <div class="form-group">
      <label class="col-sm-2 control-label no-padding-right" for="form-field-1">
        新密码：
      </label>
      <div class="col-sm-10">
        <input type="password" id="password" name="password" placeholder="请输入新登录密码" class="col-xs-10 col-sm-5" value="" />
      </div>
    </div>
    <div class="space-4"></div>

    <div class="form-group">
      <label class="col-sm-2 control-label no-padding-right" for="form-field-1">
        确认密码：
      </label>
      <div class="col-sm-10">
        <input type="password" name="confirm_password" placeholder="再次输入新登录密码" class="col-xs-10 col-sm-5" value="" />
      </div>
    </div>
    <div class="space-4"></div>

    <div class="clearfix form-actions">
      <div class="col-md-offset-3 col-md-9">
        <button class="btn btn-info" type="submit">
          <i class="ace-icon fa fa-check bigger-110"></i>
          保存
        </button>
      </div>
    </div>
  </form>
{/block}
{block name="page_js"}
  <script src="/static/plugins/jquery-validate/jquery.validate.min.js"></script>
  <script type="text/javascript">
    $(document).ready(function(){
      $("form#model-form").validate({
        rules:{
          "old_password":{
            required: true,
            remote: {
              url: "{:url('ajax_valid_password')}",
              type: "post"
            }
          },"password":{
            required: true,
            minlength: 6,
            maxlength: 20
          },"confirm_password":{
            required: true,
            equalTo: "#password"
          }
        },
        messages:{
          "old_password":{
            required: "请输入您的登录密码",
            remote: "请的登录密码不正确"
          },"password":{
            required: "请输入新登录密码",
            minlength: "登录密码长度必须在6-20之间",
            maxlength: "登录密码长度必须在6-20之间"
          },"confirm_password":{
            required: "请再次输入新登录密码",
            equalTo: "两次输入的密码不一致"
          }
        },
        errorClass: "help-inline input-error",
        errorElement: "span",
        highlight:function(element, errorClass, validClass) {
          $(element).parents('.form-group').addClass('has-error');
        },
        unhighlight: function(element, errorClass, validClass) {
          $(element).parents('.form-group').removeClass('has-error');
        },
        submitHandler: function(form){
          var $form = $(form);
          $.ajax({
            url: $form.attr("action"),
            type: $form.attr("method"),
            dataType: "JSON",
            data: $form.serialize(),
            success: function(data){
              if(data.code){
                location.href = data["url"];
              }else{
                alert(data["msg"]);
              }
            }, error: function () {
              alert("数据执行错误！");
            }
          });
        }
      });
    });
  </script>
{/block}